
	function InitAddressSelector(startCity, startInput, stopCity, stopInput, mapContainer) {
		
		var map = new BMap.Map(mapContainer);
		new BMap.LocalCity().get(function(result){
			map.centerAndZoom(result.name);
			
			startCity.attr("innerHTML", result.name);
			stopCity.attr("innerHTML", result.name);
			
			MakeAutocomplete("startAddressInput", result.name, map);
			MakeAutocomplete("stopAddressInput", result.name, map);
		});
		
		MakeCityList(startCity, stopCity, map);
		
		//MakeAutocomplete(startInput, stopInput, map);
	}
	
	function MakeCityList(startCity, stopCity, mapObj) {
		var map_popup = $('<div class="map_popup" id="cityList" style="display:none;"></div>');
		var popup_main = $('<div class="popup_main"></div>');
		var title = $('<div class="title">城市列表</div>');
		var cityList = $('<div class="cityList" id="citylist_container"></div>');
		var close_button = $('<button class="close_button" id="popup_close"></button>');
		
		map_popup.appendTo("body");
		popup_main.appendTo(map_popup);
		title.appendTo(popup_main);
		cityList.appendTo(popup_main);
		close_button.appendTo(popup_main);
		
		var myCl = new BMapLib.CityList({container : "citylist_container", map : mapObj});
		myCl.addEventListener("cityclick", function(e) {
			if ("1" == $("#start_city_selected").val()) {
				startCity.attr("innerHTML", e.name);
				MakeAutocomplete("startAddressInput", e.name, mapObj);
			}
			else {
				stopCity.attr("innerHTML", e.name);
				MakeAutocomplete("stopAddressInput", e.name, mapObj);
			}
			map_popup.css("display", "none");
		});
		
		startCity.click(function(e){
			$("#start_city_selected").val("1");
			
			var pos = startCity.offset();
			
			map_popup.css("left", pos.left);
			map_popup.css("top", pos.top);
			
			if ("none" == map_popup.css("display")) {
				map_popup.css("display", "block");
			} else {
				map_popup.css("display", "none");
			}
		});
		
		stopCity.click(function(e){
			$("#start_city_selected").val("0");
			
			var pos = stopCity.offset();
			
			map_popup.css("left", pos.left);
			map_popup.css("top", pos.top);
			
			if ("none" == map_popup.css("display")) {
				map_popup.css("display", "block");
			} else {
				map_popup.css("display", "none");
			}
		});
		
		close_button.click(function(){
			map_popup.css("display", "none");
		});
	}
	
	function MakeAutocomplete(startInputID, city, mapObj) {
		var result_type = [];
		result_type.push("all");
		
		var startAC = new BMap.Autocomplete({
			input : startInputID, 
			location : city, 
			types : result_type
		});
		
		startAC.addEventListener("onconfirm", function(e) {
			mapObj.clearOverlays();

			var obj = e.item.value;
			var address = obj.province +  obj.city +  obj.district +  obj.street +  obj.business;
			
	    var local = new BMap.LocalSearch(mapObj, {
	      onSearchComplete: function(){
	      	var pp = local.getResults().getPoi(0).point;
	        mapObj.centerAndZoom(pp, 18);
	        mapObj.addOverlay(new BMap.Marker(pp));
	      }
	    });
	    local.search(address);
		});
	}
	
	$(function(){
		$('#make_route').addClass('nav_hover');
		if(navigator.userAgent.indexOf("MSIE 6.0")!=-1){
				$('#tip').show();
		}
		
		$( "#radio" ).buttonset();
		$( "#format" ).buttonset();
		$( "#format2" ).buttonset();
		
		$( "#person_type" ).buttonset();
		
		$("#next_button_1").button();
		$("#next_button_1").click(function() {
			/*
			var $panel = $("#startAddressInput");
			box_left = ($(window).width() -  $panel.width()) / 2;
			box_left = 120;
			$panel.css({'left': box_left,'position':'absolute'});
			//for(var j=1; j<10; j++)
			for(var i=1; 4>=i; i++){
				$panel.animate({left:box_left-(40-10*i)},50);
				$panel.animate({left:box_left+2*(40-10*i)},50);
			}
			*/
			$("#slider-range-max").slider("value", 50);				
			$("#tab1").css("display", "none");
			$("#tab2").css("display", "block");
			//$("#tab1").effect("fade", {}, 1000);
			//$("#tab2").show('drop');
		});
		$("#pre_button_2").button();
		$("#pre_button_2").click(function() {
			$("#slider-range-max").slider("value", 25);
			$("#tab2").css("display", "none");
			$("#tab1").css("display", "block");
		});
		$("#next_button_2").button();
		$("#next_button_2").click(function() {
			$("#slider-range-max").slider("value", 75);
			$("#tab2").css("display", "none");
			$("#tab3").css("display", "block");
		});
		$("#pre_button_3").button();
		$("#pre_button_3").click(function() {
			$("#slider-range-max").slider("value", 50);
			$("#tab3").css("display", "none");
			$("#tab2").css("display", "block");
		});
		$("#next_button_3").button();
		$("#next_button_3").click(function() {
			$("#slider-range-max").slider("value", 100);
			$("#tab3").css("display", "none");
			$("#tab4").css("display", "block");
		});
		$("#pre_button_4").button();
		$("#pre_button_4").click(function() {
			$("#slider-range-max").slider("value", 75);
			$("#tab4").css("display", "none");
			$("#tab3").css("display", "block");
		});
		$("#button_finish").button();
		$("#button_finish").click(function() {
		});
		
		$("#radio1").change(function() {
			$("#format").css("display", "none");
		});
		$("#radio2").change(function() {
			$("#format").css("display", "block");
		});
		$("#driver").change(function() {
			$("#format2").css("display", "block");
		});
		$("#passenger").change(function() {
			$("#format2").css("display", "none");
		});
		
		$( "#slider-range-max" ).slider({
			disabled: true,
			range: "min",
			value: 25,
			animate: true,
			step: 25,
			slide: function( event, ui ) {
				//$( "#amount" ).val( ui.value );
			}
		});
	
		$('select.makeMeFancy').tzSelect({
			render : function(option){
				return $('<li>',{
					html:	'<img src="'+option.data('icon')+'" /><span>'+
						option.data('html-text')+'</span>'
				});
			},
			className : 'hasDetails'
		});
		
		// Calling the default version of the dropdown
		$('select.regularSelect').tzSelect();
		
		$.datepicker.setDefaults( $.datepicker.regional[ "zh-CN" ] );
		$( "#onDatePicker" ).datepicker({});
		$( "#offDatePicker" ).datepicker({});
		$.timepicker.setDefaults( $.datepicker.regional[ "zh-CN" ] );
		$( "#onTimePicker" ).timepicker({});
		$( "#offTimePicker" ).timepicker({});
		
		InitAddressSelector($("#startCity"), "startAddressInput", $("#stopCity"), "stopAddressInput", "map_container");
	});
	